<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title>套餐列表</title>
<link rel="stylesheet" href="/layui/css/layui.css"><script src="/static/js/jquery.min.js"></script><script src="/layui/layui.js"></script>
<style>body{background:#f5f5f5;padding:20px;}</style></head>
<body>
<div class="layui-card"><div class="layui-card-header">套餐列表 <a href="/admin/package/add" class="layui-btn layui-btn-sm layui-btn-normal" style="float:right;">添加套餐</a></div>
<div class="layui-card-body"><div class="layui-form layui-form-pane" style="margin-bottom:15px;"><div class="layui-inline"><input type="text" id="keyword" placeholder="套餐名称" class="layui-input" value="<?= htmlspecialchars($keyword) ?>"></div><div class="layui-inline"><select id="channelFilter"><option value="0">全部通道</option><?php foreach($channels as $ch): ?><option value="<?= $ch['id'] ?>" <?= $channelId==$ch['id']?'selected':'' ?>><?= $ch['name'] ?></option><?php endforeach; ?></select></div><button class="layui-btn layui-btn-primary layui-btn-sm" onclick="search()">搜索</button></div>
<table class="layui-table" lay-size="sm"><thead><tr><th>ID</th><th>套餐名称</th><th>所属通道</th><th>调用次数</th><th>价格</th><th>有效期(天)</th><th>排序</th><th>状态</th><th>操作</th></tr></thead>
<tbody><?php foreach($list as $item): ?><tr><td><?= $item['id'] ?></td><td><?= $item['name'] ?></td><td><?= $item['channel_name'] ?></td><td><?= $item['call_limit'] ?>次</td><td>¥<?= number_format($item['price'],2) ?></td><td><?= $item['valid_days'] ?></td><td><?= $item['sort'] ?></td><td><?= $item['status']?'<span style="color:green">上架</span>':'<span style="color:red">下架</span>' ?></td><td><a href="/admin/package/edit?id=<?=$item['id']?>" class="layui-btn layui-btn-xs layui-btn-normal">编辑</a> <button class="layui-btn layui-btn-xs layui-btn-warm" onclick="toggleStatus(<?=$item['id']?>)"><?=$item['status']?'下架':'上架'?></button> <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="deletePackage(<?=$item['id']?>)">删除</button></td></tr><?php endforeach; ?><?php if(empty($list)):?><tr><td colspan="9" style="text-align:center;color:#999;">暂无数据</td></tr><?php endif;?></tbody></table><div id="page"></div></div></div>
<script>
var total=<?=$total?>,page=<?=$page?>,pageSize=<?=$pageSize?>;
layui.use('laypage',function(){var p=layui.laypage;if(total>pageSize){p.render({elem:'page',count:total,limit:pageSize,curr:page,jump:function(o,f){if(!f) location.href='/admin/package/index?page='+o.curr+'&keyword=<?=urlencode($keyword)?>&channel_id=<?=$channelId?>';}});}});
function search(){location.href='/admin/package/index?keyword='+encodeURIComponent($('#keyword').val())+'&channel_id='+$('#channelFilter').val();}
function toggleStatus(id){$.post('/admin/package/toggleStatus',{id:id},function(res){layer.msg(res.msg);setTimeout(function(){location.reload();},1000);});}
function deletePackage(id){layer.confirm('确认删除？',function(){$.post('/admin/package/delete',{id:id},function(res){layer.msg(res.msg,{icon:res.code===0?1:2});if(res.code===0) setTimeout(function(){location.reload();},1000);});});}
</script></body></html>